/**
 * 销售合同 - 编辑页面
 * @author miaoyl
 * @date 2018/01/14
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        layui = win.layui,
        vueData = {
            isAdd: false,
            isDetail: false,
            gwca043Readonly: false,
            //gwca006Show: false,
            gwca004Show: false,
            AMOUNT: 100,
            form: {
                GWCAORIG_NAME: null,
                GWCAORIU_NAME: null,
                GWCAMLEGAL_NAME: null,
                GWCA001_NAME: null,
                GWCA006_NAME: null,
                GWCA007_NAME: null,
                GWGC022: null,
                GWAK009: null,
                DEVICEADDRESS: null,
                GWCA011_NAME: null,
                GWCA012_NAME: null,
                GWCA013_NAME: null,
                GWCA014_NAME: null,
                GWCA015_NAME: null,
                GWCA061_LIST: []
            },
            rules: {
                GWCAORIU_NAME: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCAORIG_NAME: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCADOCDATE: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCA002: [
                    {required: true, message: '不可为空', trigger: 'change'}
                ],
                GWCA003: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
               /* GWCA005: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],*/
                GWCA055: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWAK009: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCA007: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCAMLEGAL_NAME: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCA017: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCA018: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                /*GWCA019: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],*/
                GWCA020: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCA021: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCA023: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCA024: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCA025: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCA026: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCA029: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCA031: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCA034: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCA035: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCA036: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                /*GWCA037: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],*/
                GWCA042: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCA043: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCA001_NAME:[
                    {required: true, message: '不可为空', trigger: 'change'}
                ],
                DEVICEADDRESS:[
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCA059: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCA004:[
                    {required: true, message: '不可为空', trigger: 'blur'}
                ]
            },
            selectOptions: {
                sys_n_y: app.datas_('sys_n_y'),
                gwca002Options: app.datas_('crm_gwci001_gwca002'),
                gwca020Options: app.datas_('crm_gwci001_gwca020'),
                gwca021Options: app.datas_('crm_gwci001_gwca021'),
                gwca023Options: app.datas_('crm_gwci001_gwca023'),
                gwca027Options: app.datas_('crm_gwci001_gwca027'),
                gwca032Options: app.datas_('crm_gwci001_gwca032'),
                gwca044Options: app.datas_('crm_gwci001_gwca044'),
                gwak009Options: app.datas_('crm_gwai300_gwak009'),
                gwca011Options: [],
                gwca012Options: [],
                gwca013Options: [],
                gwca014Options: [],
                gwca015Options: [],
                gwca060Options: app.datas_('crm_gwci001_gwca060'),
                gwca025Options: app.datas_('crm_gwci001_gwca025'),
                gwca061Options: app.datas_('crm_gwgi002_gwgc007'),
            },

            uploadUrl: g_ctxPath + 'upload/files',
            file: '',
            fileList: [],
            fileList2: [],
            fileCount: 0,
        },
        cols_gwcb = [[
            {type: 'checkbox', title: '选择'}
            , {field: 'GWCBSEQ', width: 80, title: '项次'}
            , {field: 'GWCB002', width: 120, title: '产品编号', event:'openGwcb002'}
            , {field: 'GWAHL003', width: 80, title: '产品大类'}
            , {field: 'GWAOL003', width: 80, title: '车辆类型'}
            , {field: 'GWCB003', width: 100, title: '产品厂家', edit: 'select',
                filterDatas: app.datas_('crm_gwci001_gwcb003')
            }
            , {field: 'GWCB004', width: 100, title: '配置情况', edit: 'select',
                filterDatas: app.datas_('crm_gwci001_gwcb004')
            }
            , {field: 'GWCB020', width: 100, title: '配置说明', edit:'text'/*event:'openGwcb020'*/}
            , {field: 'GWCB014', width: 100, title: '底盘配置', edit:'text'/*event:'openGwcb014'*/}
            , {field: 'GWCB015', width: 100, title: '动力类型', edit:'text'/*event:'openGwcb015'*/}
            , {field: 'GWCB016', width: 100, title: '类型', edit:'text'/*event:'openGwcb016'*/}
            , {field: 'GWCB017', width: 100, title: '标配', edit:'text'/*event:'openGwcb017'*/}
            , {field: 'GWCB018', width: 100, title: '选配', edit:'text'/*event:'openGwcb018'*/}
            , {field: 'GWCB019', width: 100, title: '其他说明', edit: 'text'}
            , {field: 'GWCB013', width: 90, title: '车辆配置明细', /*edit: 'text'*//*event:'openGwcb013'*/}
            , {field: 'GWCB005_NAME', width: 100, title: '计量单位', edit: 'text'}
            , {field: 'GWCB006', width: 100, title: '数量', edit: 'text'}
            , {field: 'GWCB008', width: 100, title: '含税单价(元)', edit: 'text'}
            , {field: 'GWCB010', width: 100, title: '含税总价(元)'/*, edit: 'text'*/}
            , {field: 'GWCB007', width: 100, title: '原币单价',hide:true}
            , {field: 'GWCB009', width: 100, title: '原币总价',hide:true}
            , {field: 'GWCB012', width: 100, title: '本币未税金额',hide:true}
            , {field: 'GWCB011', width: 100, title: '本币税额',hide:true}
            , {field: 'GWCB005', width: 100, title: '单位',hide:true}

        ]],
        cols_gwcc = [[
            {type: 'checkbox', title: '选择'}
            , {field: 'GWCCSEQ', width: 80, title: '序号'}
            , {field: 'GWCC001', width: 120, title: '支付阶段', edit: 'select',
                filterDatas: app.datas_('crm_gwci001_gwcc001')
            }
            , {field: 'GWCC009', width: 120, title: '加计天数', edit: 'text'}
            , {field: 'GWCC002', width: 120, title: '收款日期', edit: 'date'}
            , {field: 'GWCC003', width: 140, title: '支付比例%', edit: 'text'}
            , {field: 'GWCC004', width: 80, title: '支付金额'/*, edit: 'text'*/}
            , {field: 'GWCC008', width: 80, title: '备注', edit: 'text'}
        ]],
        pageVue,
        table,
        callObj, layOpenIndex,
        gwcbTable, gwccTable
    ;

    var Gwci001Edit = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _tag: 'gwci001_edit',
                _loadTplsFull: [{
                    dom: 'common_open_window', tpl: '/common/_open_window'
                },{
                    dom: 'gwci001_edit_address', tpl: 'gwci001_edit_address'
                }]
            }, win);
        },

        initGwcbTable: function () {
            layui.use(['table'], function () {
                table = layui.table;
                gwcbTable = table.render({
                    elem: app.getByid(doc, 'gwci001_gwcb_table'),
                    id: 'gwci001_gwcb_table',
                    cols: cols_gwcb,
                    height: '250',
                    page: false
                });

                //监听单元格编辑
                table.on('edit(gwci001_gwcb_table)', function (obj) {
                    var oldValue = $(this).prev().text();
                    if(obj.field == 'GWCB006'){
                        var re = /(^[1-9]\d*$)/; //判断是否正整数
                        if (!re.test(obj.value)) {
                            obj.updateOfEdit({
                                GWCB006: oldValue
                            });
                            app.showWarning('数量必须为正整数！');
                            return;
                        }
                        if(obj.data.GWCB008 != ''){
                            var jiage = self.calculate(math.mul(obj.data.GWCB008, obj.value), vueData.AMOUNT); //总价
                            /*var weishui = self.calculate(math.div(jiage,math.add(1,math.div(vueData.form.GWCA050,100))), vueData.AMOUNT); //未税
                            var shuie = math.sub(jiage,weishui); //税额*/
                            obj.updateOfEdit({
                                GWCB010: jiage,
                               /* GWCB009: jiage, //原币总价
                                GWCB012: weishui, //未税金额
                                GWCB011: shuie //税额*/
                            });
                        }
                        self.getSumGwcb006();
                        self.getSumGwcb010();
                    }else if(obj.field == 'GWCB008'){
                        var reg = /^\d+(\.\d{1,4})?$/;
                        if(!reg.test(obj.value)){
                            obj.updateOfEdit({
                                GWCB008: oldValue
                            });
                            app.showWarning('单价为正数且最多输四位小数！');
                            return;
                        }
                        obj.updateOfEdit({
                            GWCB007: obj.value //原币单价
                        });
                        if(obj.data.GWCB006 != ''){
                            var jiage = self.calculate(math.mul(obj.data.GWCB006, obj.value), vueData.AMOUNT); //总价
                            /*var weishui = self.calculate(math.div(jiage,math.add(1,math.div(vueData.form.GWCA050,100))), vueData.AMOUNT); //未税
                            var shuie = math.sub(jiage,weishui); //税额*/
                            obj.updateOfEdit({
                                GWCB010: jiage,
                                /*GWCB009: jiage, //原币总价
                                GWCB012: weishui, //未税金额
                                GWCB011: shuie //税额*/
                            });
                            self.getSumGwcb010();
                        }
                    }else if(obj.field == 'GWCB010'){
                        var reg = /^(0|[1-9]\d*)(\.\d{1,2})?$/;
                        if(!reg.test(obj.value)){
                            obj.updateOfEdit({
                                GWCB010: oldValue
                            });
                            app.showWarning('金额为正数且最多输两位小数！');
                            return;
                        }
                        self.getSumGwcb010();
                        /* var weishui = self.calculate(math.div(obj.value,math.add(1,math.div(vueData.form.GWCA050,100))), vueData.AMOUNT); //未税
                         var shuie = math.sub(jiage,weishui); //税额
                         obj.updateOfEdit({
                         GWCB009: obj.value, //原币单价
                         GWCB012: weishui, //未税金额
                         GWCB011: shuie //税额
                         });*/
                    }else if(obj.field == 'GWCB020'){
                        let GWCB013 = '配置说明：' + obj.value + '<br>'
                            + '底盘配置：'+ (obj.data.GWCB014 == undefined ? '': obj.data.GWCB014 ) + '<br>'
                            + '动力类型：' + (obj.data.GWCB015 == undefined ? '' : obj.data.GWCB015) + '<br>'
                            + '类型：'+ (obj.data.GWCB016 == undefined ? '' : obj.data.GWCB016) + '<br>'
                            + '标配:'+  (obj.data.GWCB017 == undefined ? '' : obj.data.GWCB017) + '<br>'
                            + '选配:'+ (obj.data.GWCB018 == undefined ? '' : obj.data.GWCB018)+ '<br>'
                            + '其他说明:'+ (obj.data.GWCB019 == undefined ? '': obj.data.GWCB019);
                        obj.updateOfEdit({
                            GWCB013: GWCB013
                        })
                    }else if(obj.field == 'GWCB014'){
                        let GWCB013 = '配置说明：' + (obj.data.GWCB020 == undefined ? '': obj.data.GWCB020)+ '<br>'+ '底盘配置：'+ obj.value +
                            '<br>'+ '动力类型：' + (obj.data.GWCB015 == undefined ? '': obj.data.GWCB015) + '<br>'
                            + '类型：'+ (obj.data.GWCB016 == undefined ? '': obj.data.GWCB016) + '<br>'
                            + '标配:' + (obj.data.GWCB017 == undefined ? '': obj.data.GWCB017)  + '<br>'
                            + '选配:'+ (obj.data.GWCB018 == undefined ? '': obj.data.GWCB018)+ '<br>'
                            + '其他说明:'+ (obj.data.GWCB019 == undefined ? '': obj.data.GWCB019);
                        obj.updateOfEdit({
                            GWCB013: GWCB013
                        })
                    }else if(obj.field == 'GWCB015'){
                        let GWCB013 = '配置说明：' + (obj.data.GWCB020 == undefined ? '': obj.data.GWCB020)+ '<br>'
                            + '底盘配置：'+ (obj.data.GWCB014 == undefined ? '': obj.data.GWCB014) + ';<br>'+ '动力类型：' + obj.value + '</br>'
                            + '类型：'+ (obj.data.GWCB016 == undefined ? '': obj.data.GWCB016) + '<br>'
                            + '标配:'+  (obj.data.GWCB017 == undefined ? '': obj.data.GWCB017) + '<br>'
                            + '选配:'+ (obj.data.GWCB018 == undefined ? '': obj.data.GWCB018)+ '<br>'
                            + '其他说明:'+ (obj.data.GWCB019 == undefined ? '': obj.data.GWCB019);
                        obj.updateOfEdit({
                            GWCB013: GWCB013
                        })
                    }else if(obj.field == 'GWCB016'){
                        let GWCB013 = '配置说明：' + (obj.data.GWCB020 == undefined ? '': obj.data.GWCB020)+ '<br>'
                            + '底盘配置：'+ (obj.data.GWCB014 == undefined ? '' : obj.data.GWCB014) + '<br>'
                            + '动力类型：' + (obj.data.GWCB015 == undefined ? '' : obj.data.GWCB015) + '<br>'
                            + '类型：'+ obj.value + '<br>'
                            + '标配:'+  (obj.data.GWCB017 == undefined ? '' : obj.data.GWCB017) + '<br>'
                            + '选配:'+ (obj.data.GWCB018 == undefined ? '' : obj.data.GWCB018)+ '<br>'
                            + '其他说明:'+ (obj.data.GWCB019 == undefined ? '': obj.data.GWCB019);
                        obj.updateOfEdit({
                            GWCB013: GWCB013
                        })
                    }else if(obj.field == 'GWCB017'){
                        let GWCB013 = '配置说明：' + (obj.data.GWCB020 == undefined ? '': obj.data.GWCB020)+ '<br>'
                            + '底盘配置：'+ (obj.data.GWCB014 == undefined ? '': obj.data.GWCB014) + '<br>'
                            + '动力类型：' + (obj.data.GWCB015 == undefined ? '': obj.data.GWCB015) + '<br>'
                            + '类型：'+ (obj.data.GWCB016 == undefined ? '': obj.data.GWCB016) + '<br>'
                            + '标配:'+  obj.value + '<br>'
                            + '选配:'+ (obj.data.GWCB018 == undefined ? '': obj.data.GWCB018) + '<br>'
                            + '其他说明:'+ (obj.data.GWCB019 == undefined ? '': obj.data.GWCB019);
                        obj.updateOfEdit({
                            GWCB013: GWCB013
                        })
                    }else if(obj.field == 'GWCB018'){
                        let GWCB013 = '配置说明：' + (obj.data.GWCB020 == undefined ? '': obj.data.GWCB020)+ '<br>'
                            + '底盘配置：'+ (obj.data.GWCB014 == undefined ? '': obj.data.GWCB014) + '<br>'
                            + '动力类型：' + (obj.data.GWCB015 == undefined ? '': obj.data.GWCB015) + '<br>'
                            + '类型：'+ (obj.data.GWCB016 == undefined ? '': obj.data.GWCB016) + '<br>'
                            + '标配:'+  (obj.data.GWCB017 == undefined ? '': obj.data.GWCB017) + '<br>'
                            + '选配:'+ obj.value + '<br>'
                            + '其他说明:'+ (obj.data.GWCB019 == undefined ? '': obj.data.GWCB019);
                        obj.updateOfEdit({
                            GWCB013: GWCB013
                        });
                    }else if(obj.field == 'GWCB019'){
                        let GWCB013 = '配置说明：' + (obj.data.GWCB020 == undefined ? '': obj.data.GWCB020)+ '<br>'
                            + '底盘配置：'+ (obj.data.GWCB014 == undefined ? '': obj.data.GWCB014) + '<br>'
                            + '动力类型：' + (obj.data.GWCB015 == undefined ? '': obj.data.GWCB015) + '<br>'
                            + '类型：'+ (obj.data.GWCB016 == undefined ? '': obj.data.GWCB016) + '<br>'
                            + '标配:' + (obj.data.GWCB017 == undefined ? '': obj.data.GWCB017)  + '<br>'
                            + '选配:'+ (obj.data.GWCB018 == undefined ? '': obj.data.GWCB018)+ '<br>'
                            + '其他说明:'+ obj.value;
                        obj.updateOfEdit({
                            GWCB013: GWCB013
                        })
                    }
                });

                table.on('tool(gwci001_gwcb_table)', function (obj) {
                    if (obj.event == 'openGwcb002') {
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method: 'q_gwam001',
                                    columnList: [
                                        {label: '产品编号', prop: 'GWAM001', width: '150'},
                                        {label: '产品大类', prop: 'GWAHL003', width: '150'},
                                        {label: '车辆类型', prop: 'GWAOL003', width: '150'},
                                        {label: '单位', prop: 'GWABL003', width: '150'}
                                    ]
                                },
                                cb: function (data) {
                                    obj.updateOfEdit({
                                        GWCB002: data.GWAM001,
                                        GWAHL003: data.GWAHL003,
                                        GWAOL003: data.GWAOL003,
                                        GWCB005: data.GWAM008,
                                        GWCB005_NAME: data.GWABL003,
                                        GWCB014:'',
                                        GWCB015:'',
                                        GWCB016:'',
                                        GWCB017:'',
                                        GWCB018:'',
                                        GWCB019:'',
                                        GWCB013:'',
                                        GWCB006:'',
                                        GWCB008:'',
                                        GWCB010:'',
                                        GWCB003: '',
                                        GWCB004: '',
                                        GWCB020: ''
                                    });
                                    obj.update({
                                        GWCB003: '',
                                        GWCB004: ''
                                    });
                                    /*app.ajax({
                                        xurl: 'crm/gwci001/getImafuc007',
                                        xdata: {IMAFUC001: data.GWAM001},
                                        cb: function (result) {
                                            if (result.ok) {
                                                if(result.data.data.length > 0 && result.data.data[0].IMAFUC007 !== undefined) {
                                                    obj.updateOfEdit({
                                                        IMAFUC007: result.data.data[0].IMAFUC007
                                                    });
                                                }
                                            }
                                        }
                                    });*/
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择产品编号',
                                area: ['600px', '500px']
                            }
                        });
                    }else if(obj.event == 'openGwcb014'){
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method: 'q_imafuc002',
                                    columnList: [
                                        {label: '配置类型', prop: 'IMAFUC002', width: '150'}
                                    ],
                                    searchParam:{
                                        IMAFUC001: obj.data.GWCB002
                                    }
                                },
                                cb: function (data) {
                                    var IMAFUC002 = data.IMAFUC002 == undefined ? '' : data.IMAFUC002;
                                    let GWCB013 = '配置说明：' + (obj.data.GWCB020 == undefined ? '': obj.data.GWCB020)+ '<br>'+ '底盘配置：'+ IMAFUC002 +
                                        '<br>'+ '动力类型：' + (obj.data.GWCB015 == undefined ? '': obj.data.GWCB015) + '<br>'
                                        + '类型：'+ (obj.data.GWCB016 == undefined ? '': obj.data.GWCB016) + '<br>'
                                        + '标配:' + (obj.data.GWCB017 == undefined ? '': obj.data.GWCB017)  + '<br>'
                                        + '选配:'+ (obj.data.GWCB018 == undefined ? '': obj.data.GWCB018)+ '<br>'
                                        + '其他说明:'+ (obj.data.GWCB019 == undefined ? '': obj.data.GWCB019);
                                    obj.updateOfEdit({
                                        GWCB014: IMAFUC002,
                                        GWCB013: GWCB013
                                    })
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择配置类型',
                                area: ['400px', '500px']
                            }
                        });
                    }else if(obj.event == 'openGwcb015'){
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method: 'q_imafuc003',
                                    columnList: [
                                        {label: '动力类型', prop: 'IMAFUC003', width: '150'}
                                    ],
                                    searchParam:{
                                        IMAFUC001: obj.data.GWCB002
                                    }
                                },
                                cb: function (data) {
                                    var IMAFUC003 = data.IMAFUC003 == undefined ? '' : data.IMAFUC003;
                                    let GWCB013 = '配置说明：' + (obj.data.GWCB020 == undefined ? '': obj.data.GWCB020)+ '<br>'
                                        + '底盘配置：'+ (obj.data.GWCB014 == undefined ? '': obj.data.GWCB014) + ';<br>'+ '动力类型：' + IMAFUC003 + '</br>'
                                        + '类型：'+ (obj.data.GWCB016 == undefined ? '': obj.data.GWCB016) + '<br>'
                                        + '标配:'+  (obj.data.GWCB017 == undefined ? '': obj.data.GWCB017) + '<br>'
                                        + '选配:'+ (obj.data.GWCB018 == undefined ? '': obj.data.GWCB018)+ '<br>'
                                        + '其他说明:'+ (obj.data.GWCB019 == undefined ? '': obj.data.GWCB019);
                                    obj.updateOfEdit({
                                        GWCB015: IMAFUC003,
                                        GWCB013: GWCB013
                                    })
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择动力类型',
                                area: ['400px', '500px']
                            }
                        });
                    }else if(obj.event == 'openGwcb020'){
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method: 'q_imafuc007',
                                    columnList: [
                                        {label: '配置说明', prop: 'IMAFUC007', width: '150'}
                                    ],
                                    searchParam:{
                                        IMAFUC001: obj.data.GWCB002
                                    }
                                },
                                cb: function (data) {
                                    var IMAFUC007 = data.IMAFUC007 == undefined ? '' : data.IMAFUC007;
                                    let GWCB013 = '配置说明：' + IMAFUC007 + '<br>'
                                        + '底盘配置：'+ (obj.data.GWCB014 == undefined ? '': obj.data.GWCB014 ) + '<br>'
                                        + '动力类型：' + (obj.data.GWCB015 == undefined ? '' : obj.data.GWCB015) + '<br>'
                                        + '类型：'+ (obj.data.GWCB016 == undefined ? '' : obj.data.GWCB016) + '<br>'
                                        + '标配:'+  (obj.data.GWCB017 == undefined ? '' : obj.data.GWCB017) + '<br>'
                                        + '选配:'+ (obj.data.GWCB018 == undefined ? '' : obj.data.GWCB018)+ '<br>'
                                        + '其他说明:'+ (obj.data.GWCB019 == undefined ? '': obj.data.GWCB019);
                                    obj.updateOfEdit({
                                        GWCB020: IMAFUC007,
                                        GWCB013: GWCB013
                                    })
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择配置说明',
                                area: ['400px', '500px']
                            }
                        });
                    }else if(obj.event == 'openGwcb016'){
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method: 'q_imafuc004',
                                    columnList: [
                                        {label: '类型', prop: 'IMAFUC004', width: '150'}
                                    ],
                                    searchParam:{
                                        IMAFUC001: obj.data.GWCB002
                                    }
                                },
                                cb: function (data) {
                                    var IMAFUC004 = data.IMAFUC004 == undefined ? '' : data.IMAFUC004;
                                    let GWCB013 = '配置说明：' + (obj.data.GWCB020 == undefined ? '': obj.data.GWCB020)+ '<br>'
                                        + '底盘配置：'+ (obj.data.GWCB014 == undefined ? '' : obj.data.GWCB014) + '<br>'
                                        + '动力类型：' + (obj.data.GWCB015 == undefined ? '' : obj.data.GWCB015) + '<br>'
                                        + '类型：'+ IMAFUC004 + '<br>'
                                        + '标配:'+  (obj.data.GWCB017 == undefined ? '' : obj.data.GWCB017) + '<br>'
                                        + '选配:'+ (obj.data.GWCB018 == undefined ? '' : obj.data.GWCB018)+ '<br>'
                                        + '其他说明:'+ (obj.data.GWCB019 == undefined ? '': obj.data.GWCB019);
                                    obj.updateOfEdit({
                                        GWCB016: IMAFUC004,
                                        GWCB013: GWCB013
                                    })
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择类型',
                                area: ['400px', '500px']
                            }
                        });
                    }else if(obj.event == 'openGwcb017'){
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                multiple:true,
                                config: {
                                    method: 'q_imafuc006',
                                    columnList: [
                                        {label: '选项说明', prop: 'IMAFUC006', width: '150'}
                                    ],
                                    dataList:[],
                                    key:'IMAFUC006',
                                    searchParam:{
                                        IMAFUC001: obj.data.GWCB002,
                                        /*IMAFUC002:  obj.data.GWCB014,
                                        IMAFUC003:  obj.data.GWCB015,*/
                                        IMAFUC004:  obj.data.GWCB016,
                                        IMAFUC005: '1.标配',

                                    }
                                },
                                cb: function (data) {
                                    let GWCB017_ARR = "";
                                    for (var i = 0; i < data.length; i++) {
                                        GWCB017_ARR = GWCB017_ARR + data[i].IMAFUC006;
                                    }
                                    let GWCB013 = '配置说明：' + (obj.data.GWCB020 == undefined ? '': obj.data.GWCB020)+ '<br>'
                                        + '底盘配置：'+ (obj.data.GWCB014 == undefined ? '': obj.data.GWCB014) + '<br>'
                                        + '动力类型：' + (obj.data.GWCB015 == undefined ? '': obj.data.GWCB015) + '<br>'
                                        + '类型：'+ (obj.data.GWCB016 == undefined ? '': obj.data.GWCB016) + '<br>'
                                        + '标配:'+  GWCB017_ARR + '<br>'
                                        + '选配:'+ (obj.data.GWCB018 == undefined ? '': obj.data.GWCB018) + '<br>'
                                        + '其他说明:'+ (obj.data.GWCB019 == undefined ? '': obj.data.GWCB019);
                                    /*let GWCB013 = obj.data.GWCB014 + ';</br>'+ '动力类型：' + obj.data.GWCB015 + ';</br>'
                                        + '类型：'+ obj.data.GWCB016 + ';</br>'+ '标配:'+ GWCB017_ARR + ';</br>'+ '选配:'+ obj.data.GWCB018;*/
                                    obj.updateOfEdit({
                                        GWCB017: GWCB017_ARR,
                                        GWCB013: GWCB013
                                    });
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择标配类型',
                                area: ['400px', '520px']
                            }
                        });
                    }else if(obj.event == 'openGwcb018'){
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                multiple:true,
                                config: {
                                    method: 'q_imafuc006',
                                    columnList: [
                                        {label: '选项说明', prop: 'IMAFUC006', width: '150'}
                                    ],
                                    dataList:[],
                                    key:'IMAFUC006',
                                    searchParam:{
                                        IMAFUC001: obj.data.GWCB002,
                                        /*IMAFUC002:  obj.data.GWCB014,
                                        IMAFUC003:  obj.data.GWCB015,*/
                                        IMAFUC004:  obj.data.GWCB016,
                                        IMAFUC005: '2.选配',

                                    }
                                },
                                cb: function (data) {
                                    let GWCB018_ARR = "";
                                    for (var i = 0; i < data.length; i++) {
                                        GWCB018_ARR = GWCB018_ARR + data[i].IMAFUC006;
                                    }
                                    let GWCB013 = '配置说明：' + (obj.data.GWCB020 == undefined ? '': obj.data.GWCB020)+ '<br>'
                                        + '底盘配置：'+ (obj.data.GWCB014 == undefined ? '': obj.data.GWCB014) + '<br>'
                                        + '动力类型：' + (obj.data.GWCB015 == undefined ? '': obj.data.GWCB015) + '<br>'
                                        + '类型：'+ (obj.data.GWCB016 == undefined ? '': obj.data.GWCB016) + '<br>'
                                        + '标配:'+  (obj.data.GWCB017 == undefined ? '': obj.data.GWCB017) + '<br>'
                                        + '选配:'+ GWCB018_ARR + '<br>'
                                        + '其他说明:'+ (obj.data.GWCB019 == undefined ? '': obj.data.GWCB019);
                                    /*let GWCB013 = obj.data.GWCB014 + ';</br>'+ '动力类型：' + obj.data.GWCB015 + ';</br>'
                                        + '类型：'+ obj.data.GWCB016 + ';</br>'+ '标配:'+  obj.data.GWCB017 + ';</br>'+ '选配:'+ GWCB018_ARR;*/
                                    obj.updateOfEdit({
                                        GWCB018: GWCB018_ARR,
                                        GWCB013: GWCB013
                                    });
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择选配类型',
                                area: ['400px', '520px']
                            }
                        });
                    }/*else if(obj.event == 'openGwcb013'){
                        self._openTplFull({
                            tag: 'gwci001_edit_gwcb013',
                            tagData: {
                                cb: function (data) {
                                    obj.updateOfEdit({
                                        GWCB002: data.GWAM001,
                                        GWAHL003: data.GWAHL003,
                                        GWAOL003: data.GWAOL003,
                                        GWCB005: data.GWAM008,
                                        GWCB005_NAME: data.GWABL003,
                                    })
                                }
                            },
                            index: 1,
                            openOpts: {
                                title: '选择车辆配置明细',
                                area: ['600px', '470px']
                            }
                        });
                    }*/
                });
            });
        },

        initGwccTable: function () {
            layui.use(['table'], function () {
                table = layui.table;
                gwccTable = table.render({
                    elem: app.getByid(doc, 'gwci001_gwcc_table'),
                    id: 'gwci001_gwcc_table',
                    cols: cols_gwcc,
                    height: '250',
                    page: false
                });

                //监听单元格编辑
                table.on('edit(gwci001_gwcc_table)', function (obj) {
                    var oldValue = $(this).prev().text();
                    if(obj.field == 'GWCC009'){ //加计天数
                        if (isNaN(obj.value) || parseFloat(obj.value) < 0) {
                            obj.updateOfEdit({
                                GWCC003: oldValue
                            });
                            app.showWarning('加计天必须大于等于0！');
                            return;
                        }
                        if(vueData.form.GWCA036 != null && vueData.form.GWCA036 != '' && obj.data.GWCC001 === '1'){
                            let GWCC002 = self.getGwcc002(vueData.form.GWCA036, obj.value);
                            obj.updateOfEdit({
                                GWCC002: GWCC002
                            });
                        }
                    }else if(obj.field == 'GWCC003'){ //支付比例
                        if (isNaN(obj.value) || parseFloat(obj.value) <= 0 || parseFloat(obj.value) > 100) {
                            obj.updateOfEdit({
                                GWCC003: oldValue
                            });
                            app.showWarning('支付比例必须为大于0小于等于100的数据！');
                            return;
                        }
                        if(vueData.form.GWCA041 != '' && vueData.form.GWCA041 != null){
                            obj.updateOfEdit({
                                GWCC004: math.mul(math.div(obj.value,100), vueData.form.GWCA041)
                            });
                        }
                    }else if(obj.field == 'GWCC004'){//金额
                        var reg = /^(0|[1-9]\d*)(\.\d{1,2})?$/;
                        if(!reg.test(obj.value)){
                            obj.updateOfEdit({
                                GWCC004: oldValue
                            });
                            app.showWarning('金额为正数且最多输两位小数！');
                            return;
                        }
                    }else if (obj.field == 'GWCC002'){
                        obj.updateOfEdit({
                            GWCC002: new Date(obj.value).Format("yyyy-MM-dd")
                        });
                    }
                });

                table.on('tool(gwci001_gwcc_table)', function (obj) {

                });
            });
        },

        getGwcc002:function (value1, value2) {
            let day = math.mul(math.mul(math.mul(math.mul(value2, 24), 60),60),1000);
            return new Date(new Date(value1).getTime() + day).Format("yyyy-MM-dd");
        },

        getSumGwcb006:function () { //回写总数量
            let sum = 0;
            var gwcbList = gwcbTable.getDatas();
            gwcbList.forEach(function (item) {
                if(item.GWCB006 != '' && item.GWCB006 != undefined){
                    sum = math.add(sum, item.GWCB006);
                }
            });
            if(sum == 0){
                pageVue.form.GWCA040 = '';
            }else {
                vueData.form.GWCA040 = sum;
            }
        },

        getSumGwcb010:function () { //回写总金额
            let sum = 0;
            var gwcbList = gwcbTable.getDatas();
            var gwccList = gwccTable.getDatas();
            gwcbList.forEach(function (item) {
                if(item.GWCB010 != '' && item.GWCB010 != undefined){
                    sum = math.add(sum, item.GWCB010);
                }
            });
            if(sum == 0){
                pageVue.form.GWCA041 = '';
            }else {
                vueData.form.GWCA041 = sum;
            }
            if(gwccList.length > 0) {
                gwccList.forEach(function (v) {
                    if (v.GWCC003 != '') {
                        v.GWCC004 = math.mul(math.div(v.GWCC003,100), sum);
                    }
                });
                self.gwccTableReload(gwccList);
            }
        },

        editData: function (gwcbData, gwccData) {
            app.ajax({
                xurl: 'crm/gwci001/editData',
                xdata: {gwcbList:gwcbData,gwccList:gwccData,gwcaData:vueData.form},
                loading: true,
                toJsonStr: true,
                // okmsg: '销售合同修改成功',
                cb: function (result) {
                    if (result.ok) {
                        //同步更新缓存对应的值
                        //callObj.update(result.xdata);
                        if(result.data.data.code == 500){
                            app.showError("销售合同保存失败");
                            layui.layer.open({
                                type: 1,
                                shade: false,
                                title: false, //不显示标题
                                area:['600px','400px'],
                                content: "报错信息："+result.data.data.msg, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
                                cancel: function(){
                                }
                            });
                        }else {
                            vueData.fileList = [];
                            vueData.fileList2 = [];
                            app.showSuccess("销售合同保存成功");
                            app.pageModule('gwci001').reloadTableCurr();
                            layer.close(layOpenIndex);
                        }
                    }
                }
            });
        },

        addData: function (gwcbData, gwccData) {
            app.ajax({
                xurl: 'crm/gwci001/addData',
                xdata: {gwcbList:gwcbData,gwccList:gwccData,gwcaData:vueData.form},
                loading: true,
                toJsonStr: true,
                //okmsg: '销售合同保存成功',
                cb: function (result) {
                    if (result.ok) {
                        if(result.data.data.code == 500){
                            app.showError("销售合同保存失败");
                            layui.layer.open({
                                type: 1,
                                shade: false,
                                title: false, //不显示标题
                                area:['600px','400px'],
                                content: "报错信息："+result.data.data.msg, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
                                cancel: function(){
                                }
                            });
                        }else {
                            vueData.fileList = [];
                            vueData.fileList2 = [];
                            app.showSuccess("销售合同保存成功");
                            app.pageModule('gwci001').reloadTableCurr();
                            layer.close(layOpenIndex);
                        }
                    }
                }
            });
        },

        calculate:function (num, digit) {
            var data = math.div(Math.round(math.mul(num, digit)),digit);
            return data;
        },

        _call: function (obj) {
            pageVue.$refs['form'].resetFields();
            layOpenIndex = obj.layOpenIndex;
            vueData.fileList = [];
            vueData.fileList2 = [];
            vueData.fileCount = 0;
            if(obj.is_detail){
                vueData.isDetail = true;
            }else {
                vueData.isDetail = false;
            }
            if (obj.is_add) {
                vueData.isAdd = true;
                app.ajax({
                    xurl: 'crm/gwci001/getAddData',
                    xdata: {},
                    cb: function (result) {
                        if (result.ok) {
                            app.extendUpLow({
                                target: vueData.form,
                                res: [result.data.data,{
                                    GWCAACTI : 'N'
                                }],
                                reset: true
                            });
                        }
                    }
                });
                self.gwcbTableReload([]);
                self.gwccTableReload([]);
            } else {
                vueData.isAdd = false;
                callObj = obj.obj;
                if(callObj.data.GWCAACTI !== "N" && callObj.data.GWCAACTI !== "R") {
                    vueData.isDetail = true;
                }
                app.extendUpLow({
                    target: vueData.form,
                    res: callObj.data,
                    reset: true
                });

                vueData.form.GWCA061_LIST = callObj.data.GWCA061 == undefined ? []: callObj.data.GWCA061.split(";");

                if (callObj.data.GWCA062 != undefined && callObj.data.GWCA062 != "") {
                    if (callObj.data.GWCA062.length > 0) {

                        let list = callObj.data.GWCA062.split(',');
                        for (let i = 0; i < list.length; i++) {
                            vueData.fileList.push({
                                name: list[i], url: '/wissun-smfile/' + list[i]
                            });
                            vueData.fileList2.push({GWCA062: list[i]});
                        }
                    }
                }

                app.ajax({
                    xurl: 'crm/gwci001/getTable',
                    xdata: {GWCADOCNO: callObj.data.GWCADOCNO},
                    cb: function (result) {
                        if (result.ok) {
                            var gwcbList = result.data.data.gwcbList;
                            var gwccList = result.data.data.gwccList;
                            self.gwcbTableReload(gwcbList);
                            self.gwccTableReload(gwccList);
                        }
                    }
                });
                //self.getAddress();
            }
            pageVue.$nextTick(function(){  //使用vue.$nextTick()方法可以dom数据更新后延迟执行
                pageVue.$refs['form'].clearValidate();
            });
        },

        gwcbTableReload: function (listData) {
            self._reloadTable({id: 'gwci001_gwcb_table', data: listData});
        },

        gwccTableReload: function (listData) {
            self._reloadTable({id: 'gwci001_gwcc_table', data: listData});
        },

        getGwakData:function (GWAK001) {
            //根据客户获取组织形式、客户的发货地址(联系人中有发货类型的资料)、负责人、负责人电话、税种、税率(根据税种取税种基本资料)、币别、汇率类型、汇率
            app.ajax({
                xurl: 'crm/gwci001/getGwakData',
                xdata: {GWAK001: GWAK001},
                cb: function (result) {
                    if (result.ok) {
                        var gwakData = result.data.data;
                        vueData.form.GWCA049 = gwakData.GWAK012;//税种
                        vueData.form.GWCA050 = gwakData.GWEA006;//税率
                        vueData.form.GWCA051 = gwakData.GWAK008;//币种
                        vueData.form.GWCA052 = gwakData.GWAK008;//汇率类型
                        vueData.form.GWCA053 = gwakData.huilv;//汇率
                        vueData.form.GWCA017 = gwakData.GWAK031;//主办人
                        vueData.form.GWCA018 = gwakData.GWAK030;//负责人电话
                        vueData.form.GWAK009 = gwakData.GWAK009;//组织形式
                        vueData.form.GWCA011 = gwakData.GWAK023;
                        vueData.form.GWCA012 = gwakData.GWAK024;
                        vueData.form.GWCA013 = gwakData.GWAK025;
                        vueData.form.GWCA014 = gwakData.GWAK026;
                        vueData.form.GWCA015 = gwakData.GWAK027;
                        vueData.form.GWCA016 = gwakData.GWAK028;
                        vueData.form.DEVICEADDRESS =  gwakData.DEVICEADDRESS;
                        //送货地址
                        /*if(gwakData.gwalList != null && gwakData.gwalList.length > 0){
                            vueData.form.GWCA008 = gwakData.gwalList[0].GWAL010;
                            vueData.form.GWCA009 = gwakData.gwalList[0].GWAL011;
                            vueData.form.GWCA010 = gwakData.gwalList[0].GWAL012;
                            vueData.form.GWCA011 = gwakData.gwalList[0].GWAL013;
                            vueData.form.GWCA012 = gwakData.gwalList[0].GWAL014;
                            vueData.form.GWCA013 = gwakData.gwalList[0].GWAL015;
                            vueData.form.GWCA014 = gwakData.gwalList[0].GWAL016;
                            vueData.form.GWCA015 = gwakData.gwalList[0].GWAL017;
                            vueData.form.GWCA016 = gwakData.gwalList[0].GWAL018;
                            self.getAddress();
                        }*/
                    }
                }
            });
        },

        getAddress:function () {
            //console.log('vueData.form',vueData.form);
            vueData.selectOptions.gwca012Options = [];
            app.ajax({
                xurl: 'crm/gwai300/getGwadList',
                xdata: {gwad001: '5', gwad003: vueData.form.GWCA011, type: '4'},
                cb: function (result) {
                    vueData.selectOptions.gwca012Options.pushArray(result.data.data);
                }
            });
            vueData.selectOptions.gwca013Options = [];
            app.ajax({
                xurl: 'crm/gwai300/getGwadList',
                xdata: {gwad001: '6', gwad003: vueData.form.GWCA012, type: '5'},
                cb: function (result) {
                    vueData.selectOptions.gwca013Options.pushArray(result.data.data);
                }
            });
            vueData.selectOptions.gwca014Options = [];
            app.ajax({
                xurl: 'crm/gwai300/getGwadList',
                xdata: {gwad001: '7', gwad003: vueData.form.GWCA013, type: '6'},
                cb: function (result) {
                    vueData.selectOptions.gwca014Options.pushArray(result.data.data);
                }
            });
            vueData.selectOptions.gwca015Options = [];
            app.ajax({
                xurl: 'crm/gwai300/getGwadList',
                xdata: {gwad001: '8', gwad003: vueData.form.GWCA014, type: '7'},
                cb: function (result) {
                    vueData.selectOptions.gwca015Options.pushArray(result.data.data);
                }
            });
        },

        _ready: function () {
            vueData.form = app.fields_(['GWCA_T'], vueData.form);
            pageVue = new Vue({
                el: '#gwci001_edit',
                data: vueData,
                methods: {
                    openGwca001: function () {//销售地区开窗
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method:'q_gwad002',
                                    columnList: [
                                        {label: '区域编号', prop: 'GWAD002', width: '150'},
                                        {label: '区域名称', prop: 'GWADL004', width: '150'},
                                        {label: '助记码', prop: 'GWADL005', width: '150'}
                                    ],
                                    searchParam: {
                                        GWAD001: "4"
                                    },
                                },
                                cb: function (data) {
                                    vueData.form.GWCA001 = data.GWAD002;
                                    vueData.form.GWCA001_NAME = data.GWADL004;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择销售地区',
                                area: ['600px', '465px']
                            }
                        });
                    },
                    openGwca004: function () {//招标编号开窗
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method:'q_gwgc001',
                                    columnList: [
                                        {label: '投标ID', prop: 'GWGCID', width: '150'},
                                        {label: '招标编号', prop: 'GWGC001', width: '150'},
                                        {label: '项目名称', prop: 'GWGC022', width: '150'},
                                        {label: '客户', prop: 'GWGC023_NAME', width: '150'}
                                    ],
                                    searchParam:{
                                        GWGC014: 'Y',
                                        GWGCACTI: 'Y'
                                    }
                                },
                                cb: function (data) {
                                    vueData.form.GWCAID = data.GWGCID;
                                    vueData.form.GWCA004 = data.GWGC001;
                                    vueData.form.GWGC022 = data.GWGC022;
                                    vueData.form.GWCA055 = data.GWGC023_NAME;
                                    vueData.form.GWCA006 = data.GWGC023;
                                    self.getGwakData(data.GWGC023);
                                    //vueData.gwca006Show = true;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择招标信息',
                                area: ['600px', '465px']
                            }
                        });
                    },
                    openGwca006: function () {//客户单位
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method: 'cq_gwak001_6',
                                    columnList: [
                                        {label: '客户编号', prop: 'GWAK001', width: '200'},
                                        {label: '名称', prop: 'GWAKL004', width: '200'}
                                    ],
                                    searchParam:{
                                        GWBZ002: 'A',
                                        GWAKACTI: 'F'
                                    }
                                },
                                cb: function (data) {
                                    vueData.form.GWCA006 = data.GWAK001;
                                    vueData.form.GWCA055 = data.GWAKL004;
                                    self.getGwakData(data.GWAK001);
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择客户单位',
                                area: ['600px', '470px']
                            }
                        });
                    },
                    openGwca007: function () {//最终用户
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method: 'q_gwak001',
                                    columnList: [
                                        {label: '客户编号', prop: 'GWAK001', width: '200'},
                                        {label: '名称', prop: 'GWAKL004', width: '200'}
                                    ],
                                },
                                cb: function (data) {
                                    vueData.form.GWCA007 = data.GWAK001;
                                    vueData.form.GWCA007_NAME = data.GWAKL004;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择最终用户',
                                area: ['600px', '470px']
                            }
                        });
                    },
                    openGwcamlegal:function() {//合同签订组织
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method: 'q_sysorg_biz',
                                    columnList: [
                                        {label: '组织编号', prop: 'ID', width: '150'},
                                        {label: '名称', prop: 'NAME', width: '150'}
                                    ],
                                },
                                cb: function (data) {
                                    vueData.form.GWCAMLEGAL = data.ID;
                                    vueData.form.GWCAMLEGAL_NAME = data.NAME;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择合同签订组织',
                                area: ['600px', '470px']
                            }
                        });
                    },
                    cancel: function () {
                        layer.close(layOpenIndex);
                    },
                    sure: function () {
                        this.$refs['form'].validate(function (valid) {
                            if (valid) {
                                var flag = true;
                                var gwcbData = gwcbTable.getDatas();
                                var gwccData = gwccTable.getDatas();
                                let gwcc003Sum = 0;
                                if(gwcbData.length < 1){
                                    app.showWarning("合同明细不能为空！");
                                    return;
                                }else {
                                    gwcbData.forEach(function (v) {
                                        if(v.GWCB002 === '' || v.GWCB002 === undefined){
                                            app.showWarning('产品不能为空！');
                                            flag = false;
                                            return;
                                        }
                                        if(v.GWCB003 === '' || v.GWCB003 === undefined){
                                            app.showWarning('产品厂家不能为空！');
                                            flag = false;
                                            return;
                                        }
                                        if(v.GWCB004 === '' || v.GWCB004 === undefined){
                                            app.showWarning('配置情况不能为空！');
                                            flag = false;
                                            return;
                                        }
                                        if(v.GWCB005 === '' || v.GWCB005 === undefined){
                                            app.showWarning('计量单位不能为空！');
                                            flag = false;
                                            return;
                                        }
                                        if(v.GWCB006 === '' || v.GWCB006 === undefined){
                                            app.showWarning('数量不能为空！');
                                            flag = false;
                                            return;
                                        }
                                        if( v.GWCB008 === '' || v.GWCB008 === undefined){
                                            app.showWarning('含税单价不能为空！');
                                            flag = false;
                                            return;
                                        }
                                        if(v.GWCB010 === '' || v.GWCB010 === undefined){
                                            app.showWarning('含税总价不能为空！');
                                            flag = false;
                                            return;
                                        }
                                        if(v.GWCB013 === '' || v.GWCB013 === undefined){
                                            app.showWarning('车辆配置明细不能为空！');
                                            flag = false;
                                            return;
                                        }
                                    });
                                }
                                if(flag) {
                                    if(gwccData.length > 0){
                                        gwccData.forEach(function (v) {
                                            if(v.GWCC001 === '' || v.GWCC001 === undefined){
                                                app.showWarning('支付阶段必输！');
                                                flag = false;
                                                return;
                                            }
                                            if(v.GWCC003 === '' || v.GWCC003 === undefined){
                                                app.showWarning('支付比例必输！');
                                                flag = false;
                                                return;
                                            }
                                            if(v.GWCC004 === '' || v.GWCC004 === undefined){
                                                app.showWarning('支付金额必输！');
                                                flag = false;
                                                return;
                                            }
                                            if(v.GWCC009 === '' || v.GWCC009 === undefined){
                                                app.showWarning('加计天数必输！');
                                                flag = false;
                                                return;
                                            }
                                            if(v.GWCC001 == '5' && (v.GWCC002 == '' || v.GWCC002 == undefined)){
                                                app.showWarning('支付阶段为5.指定时间,收款日期必填！');
                                                flag = false;
                                                return;
                                            }
                                            gwcc003Sum = math.add(gwcc003Sum, v.GWCC003);
                                        });
                                    }
                                    if(flag) {
                                        if (gwccData.length > 0 && gwcc003Sum != 100) {
                                            app.showWarning('支付总比例需为100！');
                                            return;
                                        }
                                        vueData.form.GWCA061 = vueData.form.GWCA061_LIST.join(";");

                                        if (vueData.isAdd) {
                                            let fileFlag = true;
                                            if (pageVue.$refs.upload2.uploadFiles.length > 0) {
                                                fileFlag = false;
                                                pageVue.$refs.upload2.submit();
                                            }
                                            if (fileFlag) {
                                                self.addData(gwcbData, gwccData);
                                            }
                                        } else {
                                            vueData.form.GWCA062 = '';
                                            // 将文件链接拼接起来
                                            let gwca062s = [];
                                            for (var i = 0; i < vueData.fileList2.length; i++) {
                                                gwca062s[i] = vueData.fileList2[i].GWCA062;
                                            }
                                            vueData.form.GWCA062 = gwca062s.join(",");

                                            // 将没有改动过的文件从上传列表中删掉
                                            vueData.fileList2.forEach(function (v) {
                                                pageVue.$refs.upload2.uploadFiles.removeByMap({
                                                    name: v.GWCA062
                                                });
                                            });

                                            let fileFlag = true;
                                            if (pageVue.$refs.upload2.uploadFiles.length > 0) {
                                                fileFlag = false;
                                                pageVue.$refs.upload2.submit();
                                            }
                                            if (fileFlag) {
                                                self.editData(gwcbData, gwccData);
                                            }
                                        }
                                    }
                                }
                            }
                        });
                    },
                    addGwcb:function () {
                        var choose_data = gwcbTable.getDatas();
                        var count = 0;
                        if(choose_data.length > 0) {
                            count = choose_data[choose_data.length - 1].GWCBSEQ;
                        }
                        choose_data.push({
                            GWCBSEQ: count+1,
                            GWCB002: '',
                            GWAHL003: '',
                            GWAOL003: '',
                            GWCB003: '',
                            GWCB004: '',
                            GWCB013: '',
                            GWCB005: '',
                            GWCB006: '',
                            GWCB007: '',
                            GWCB008: '',
                            GWCB009: '',
                            GWCB010: '',
                            GWCB011: '',
                            GWCB012: '',
                            GWCB014: '',
                            GWCB015: '',
                            GWCB016: '',
                            GWCB017: '',
                            GWCB018: '',
                            GWCB019: '',
                            GWCB020: ''
                        });
                        self.gwcbTableReload(choose_data);
                    },
                    delGwcb:function () {
                        var listData = gwcbTable.getDatas();
                        var checkStatus = table.checkStatus('gwci001_gwcb_table');
                        if (checkStatus.data.length > 0) {
                            checkStatus.data.forEach(function (v) {
                                listData.removeByMap({
                                    GWCBSEQ: v.GWCBSEQ
                                });
                            });
                            if (checkStatus.length != 0) {
                                var i = 1;
                                listData.forEach(function (v) {
                                    v.GWCBSEQ = i;
                                    i++;
                                });
                            }
                            self.getSumGwcb006();
                            self.getSumGwcb010();
                            self.gwcbTableReload(listData);
                        }
                    },
                    addGwcc:function () {
                        var choose_data = gwccTable.getDatas();
                        var count = 0;
                        if(choose_data.length > 0) {
                            count = choose_data[choose_data.length - 1].GWCCSEQ;
                        }
                        choose_data.push({
                            GWCCSEQ: count+1,
                            GWCC001: '',
                            GWCC002: '',
                            GWCC003: '',
                            GWCC004: '',
                            GWCC008: '',
                            GWCC009: ''
                        });
                        self.gwccTableReload(choose_data);
                    },
                    delGwcc:function () {
                        var listData = gwccTable.getDatas();
                        var checkStatus = table.checkStatus('gwci001_gwcc_table');
                        if (checkStatus.data.length > 0) {
                            checkStatus.data.forEach(function (v) {
                                listData.removeByMap({
                                    GWCCSEQ: v.GWCCSEQ
                                });
                            });
                            if (checkStatus.length != 0) {
                                var i = 1;
                                listData.forEach(function (v) {
                                    v.GWCCSEQ = i;
                                    i++;
                                });
                            }
                            self.gwccTableReload(listData);
                        }
                    },
                    changeGwca011: function (val) {
                        var obj = {};
                        obj = vueData.selectOptions.gwca011Options.find(function (item) {
                            return item.GWAD002 === val
                        });
                        pageVue.form.GWCA012 = "";
                        pageVue.form.GWCA013 = "";
                        pageVue.form.GWCA014 = "";
                        pageVue.form.GWCA015 = "";
                        pageVue.form.GWCA016 = "";
                        vueData.selectOptions.gwca012Options = [];
                        app.ajax({
                            xurl: 'crm/gwai300/getGwadList',
                            xdata: {gwad001: '5', gwad003: vueData.form.GWCA011, type: '4'},
                            cb: function (result) {
                                vueData.selectOptions.gwca012Options.pushArray(result.data.data);
                            }
                        });
                    },
                    changeGwca012: function (val) {
                        var obj = {};
                        obj = vueData.selectOptions.gwca012Options.find(function (item) {
                            return item.GWAD002 === val
                        });
                        pageVue.form.GWCA013 = "";
                        pageVue.form.GWCA014 = "";
                        pageVue.form.GWCA015 = "";
                        pageVue.form.GWCA016 = "";
                        vueData.selectOptions.gwca013Options = [];
                        app.ajax({
                            xurl: 'crm/gwai300/getGwadList',
                            xdata: {gwad001: '6', gwad003: vueData.form.GWCA012, type: '5'},
                            cb: function (result) {
                                vueData.selectOptions.gwca013Options.pushArray(result.data.data);
                            }
                        });
                    },
                    changeGwca013: function (val) {
                        var obj = {};
                        obj = vueData.selectOptions.gwca013Options.find(function (item) {
                            return item.GWAD002 === val
                        });
                        pageVue.form.GWCA014 = "";
                        pageVue.form.GWCA015 = "";
                        pageVue.form.GWCA016 = "";
                        vueData.selectOptions.gwca014Options = [];
                        app.ajax({
                            xurl: 'crm/gwai300/getGwadList',
                            xdata: {gwad001: '7', gwad003: vueData.form.GWCA013, type: '6'},
                            cb: function (result) {
                                vueData.selectOptions.gwca014Options.pushArray(result.data.data);
                            }
                        });
                    },
                    changeGwca014: function (val) {
                        var obj = {};
                        obj = vueData.selectOptions.gwca014Options.find(function (item) {
                            return item.GWAD002 === val
                        });
                        pageVue.form.GWCA015 = "";
                        pageVue.form.GWCA016 = "";
                        vueData.selectOptions.gwca015Options = [];
                        app.ajax({
                            xurl: 'crm/gwai300/getGwadList',
                            xdata: {gwad001: '8', gwad003: vueData.form.GWCA014, type: '7'},
                            cb: function (result) {
                                vueData.selectOptions.gwca015Options.pushArray(result.data.data);
                            }
                        });
                    },
                    changeGwca015: function (val) {
                        var obj = {};
                        obj = vueData.selectOptions.gwca015Options.find(function (item) {
                            return item.GWAD002 === val
                        });
                        pageVue.form.GWCA016 = "";
                    },
                    changeGwca036:function (val) {
                        var listData = gwccTable.getDatas();
                        if(listData.length > 0) {
                            listData.forEach(function (v) {
                                if(v.GWCC009 != null && v.GWCC009 != undefined && v.GWCC009 != '' && v.GWCC002 === '1'){
                                    let GWCC002 = self.getGwcc002(val, v.GWCC009);
                                    v.GWCC002 = GWCC002;
                                }
                            });
                            self.gwccTableReload(listData);
                        }
                    },
                    openDeviceAddress:function () {
                        self._openTplFull({
                            tag: 'gwci001_edit_address',
                            tagData: {
                                data:vueData.form,
                                cb: function (data) {
                                    vueData.form.DEVICEADDRESS = data.DEVICEADDRESS;
                                    vueData.form.GWCA011_NAME = data.GWCA011_NAME;
                                    vueData.form.GWCA012_NAME = data.GWCA012_NAME;
                                    vueData.form.GWCA013_NAME = data.GWCA013_NAME;
                                    vueData.form.GWCA014_NAME = data.GWCA014_NAME;
                                    vueData.form.GWCA015_NAME = data.GWCA015_NAME;
                                    vueData.form.GWCA011 = data.GWCA011;
                                    vueData.form.GWCA012 = data.GWCA012;
                                    vueData.form.GWCA013 = data.GWCA013;
                                    vueData.form.GWCA014 = data.GWCA014;
                                    vueData.form.GWCA015 = data.GWCA015;
                                    vueData.form.GWCA016 = data.GWCA016;
                                }
                            },
                            index: 1,
                            openOpts: {
                                title: '选择设备使用地点',
                                area: ['800px', '400px']
                            }
                        });
                    },


                    handleFilePreview: function (file) {
                        window.open('/smfile/' + file.name);
                    },
                    handleExceed: function (files, fileList) {
                        this.$message.warning("当前只允许选择一个文件，如果需要选择新的文件，请先删除之前的文件!");
                    },
                    handleFileRemove: function (file, fileList) {
                        if (!vueData.isAdd) {
                            vueData.fileList2.removeByMap({
                                GWCA062: file.name
                            });
                        }
                    },
                    beforeUploadFiles: function (file) {
                        const isJPG = (file.type === 'application/pdf'
                            || file.type === 'text/plain'
                            || file.type === 'application/msword' || file.type === 'application/vnd.ms-excel'
                            || file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
                            || file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/gif'
                            || file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document');
                        const isLt10M = file.size / 1024 / 1024 < 10;
                        if (!isJPG) {
                            this.$message.error('文件格式不对');
                        }
                        if (!isLt10M) {
                            this.$message.error('文件最多为10M');
                        }
                        return isJPG && isLt10M;
                    },
                    successUploadFiles: function (response) {
                        if (response.code === 200) {
                            if (vueData.form.GWCA062 === '' || vueData.form.GWCA062 == null) {
                                vueData.form.GWCA062 = response.data[0].name;
                            } else {
                                vueData.form.GWCA062 = vueData.form.GWCA062 + ',' + response.data[0].name;
                            }

                            vueData.fileCount++;
                            if (vueData.fileCount === pageVue.$refs.upload2.uploadFiles.length) {
                                pageVue.$message.success('文件上传成功');
                                var gwcbData = gwcbTable.getDatas();
                                var gwccData = gwccTable.getDatas();
                                if (vueData.isAdd) {
                                    self.addData(gwcbData, gwccData);
                                } else {
                                    self.editData(gwcbData, gwccData);
                                }
                                pageVue.$refs.upload2.clearFiles();
                            }
                        }
                    },
                },
                created: function () {
                    self._setEleIsReady('gwci001_edit');
                },
                watch: {
                    'form.GWCA004': function () {
                       if(vueData.form.GWCA004 == '' || vueData.form.GWCA004 == null){
                           vueData.form.GWGC022 = '';
                           //vueData.gwca006Show = false;
                       }
                    },
                    'form.GWCA031': function (newValue) {
                       if(newValue === '' ||  newValue == null || newValue === "N"){
                           vueData.form.GWCA032 = '';
                           vueData.form.GWCA033 = '';
                       }
                    },

                    'form.GWCA042': function () {
                        if(vueData.form.GWCA042 == 'Y'){
                            vueData.gwca043Readonly = true;
                            vueData.form.GWCA043 = vueData.form.GWCA055;
                        }else {
                            vueData.gwca043Readonly = false;
                            //vueData.form.GWCA043 = '';
                        }
                    },
                    'form.DEVICEADDRESS': function () {
                        if(vueData.form.DEVICEADDRESS == '' || vueData.form.DEVICEADDRESS == null){
                            vueData.form.GWCA011_NAME = '';
                            vueData.form.GWCA012_NAME = '';
                            vueData.form.GWCA013_NAME = '';
                            vueData.form.GWCA014_NAME = '';
                            vueData.form.GWCA015_NAME = '';
                            vueData.form.GWCA011 = '';
                            vueData.form.GWCA012 = '';
                            vueData.form.GWCA013 = '';
                            vueData.form.GWCA014 = '';
                            vueData.form.GWCA015 = '';
                            vueData.form.GWCA016 = '';
                        }
                    },
                    'form.GWCA003': function () {
                        if(vueData.form.GWCA003 == 'Y'){
                            vueData.gwca004Show = true;
                        }else {
                            vueData.gwca004Show = false;
                            vueData.form.GWCA004 = '';
                            vueData.form.GWGC022 = '';
                        }
                    }
                }
            });

            self.initGwcbTable();
            self.initGwccTable();
        },

        _lazy: function () {
            this._super();

            app.ajax({
                xurl: 'admin/getDigit',
                cb: function (result) {
                    if(result.ok) {
                        var data = result.data.data;
                        vueData.AMOUNT = Math.pow(10,data.amount);
                    }else {
                        console.log("获取小数位失败");
                    }
                }
            });

            app.ajax({
                xurl: 'crm/gwai300/getGwadList',
                xdata: {gwad001: '4', type: '3'},
                cb: function (result) {
                    vueData.selectOptions.gwca011Options.pushArray(result.data.data);
                }
            });
        }
    });

    return new Gwci001Edit();

});